local zhanwang = fk.CreateSkill {
  name = "th_zhanwang",
}

zhanwang:addEffect(fk.EventPhaseStart, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return target.phase == Player.Play and player:hasSkill(zhanwang.name) and not player:isKongcheng() and not target.dead
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local all_names = {}
    local names = {}
    for _, name in ipairs(Fk:getAllCardNames("bt")) do
      local card = Fk:cloneCard(name)
      if card:isCommonTrick() or card.trueName == "analeptic" then
        if ((card.skill:getMinTargetNum(target) == 0 and not card.multiple_targets) or card.skill:getMinTargetNum(target) == 1) and
        card.skill:canUse(target, card, { bypass_times = true }) and card.skill:modTargetFilter(target, target, {}, card, { bypass_times = true }) then
          table.insertIfNeed(all_names, card.name)
          if target:canUseTo(card, target) then
            table.insertIfNeed(names, card.name)
          end
        end
      end
    end
    local _, ret = room:askToUseActiveSkill(player, {
      skill_name = "#th_zhanwang_active",
      prompt = "#th_zhanwang-invoke::"..target.id,
      cancelable = true,
      extra_data = {
        skillName = zhanwang.name,
        vs_names = names,
        vs_all_names = all_names,
        tos = { target },
      }
    })
    if ret then
      event:setCostData(self, { tos = ret.targets, cards = ret.cards, interaction = ret.interaction })
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local dat = event:getCostData(self)
    local card, use_name = dat.cards, dat.interaction
    room:throwCard(card, zhanwang.name, player, player)
    if not target.dead then
      room:useVirtualCard(use_name, nil, target, target, zhanwang.name, false)
      if not target.dead and target ~= player then
        room:loseHp(target, 1, zhanwang.name)
      end
    end
  end,
})

Fk:loadTranslationTable{
  ["th_zhanwang"] = "谵妄",
  [":th_zhanwang"] = "一名角色的出牌阶段开始时，你可以弃置一张手牌并声明一张【酒】或普通锦囊牌，令其视为对自己使用之，然后若其不为你，其失去1点体力。",

  ["#th_zhanwang-invoke"] = "谵妄：你可以弃置一张牌并声明一张【酒】或普通锦囊牌，令 %dest 视为对自己使用之",
}

return zhanwang